package com.tanhua.server.controller;

import com.tanhua.server.service.VideoService;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 发布小视频
     *
     * @param picFile
     * @param videoFile
     * @return
     */
    @PostMapping
    public Object saveVideo(@RequestParam("videoThumbnail") MultipartFile picFile,
                            @RequestParam("videoFile") MultipartFile videoFile) {
        return this.videoService.saveVideo(picFile, videoFile);
    }

    /**
     * 查询小视频列表
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping
    public PageResult queryVideoList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return this.videoService.queryVideoList(Math.max(page, 1), pageSize);
    }

    @PostMapping("/{id}/like")
    public Long likeVideo(@PathVariable("id") String publishId) {

        return this.videoService.likeComment(publishId);
    }

    @PostMapping("/{id}/dislike")
    public Long dislikeVideo(@PathVariable("id") String publishId) {
        return this.videoService.disLikeComment(publishId);
    }

    @GetMapping("/{id}/comments")
    public PageResult queryCommentsList(@PathVariable("id") String id,
                                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return this.videoService.queryCommentList(id, page, pageSize);
    }

    @PostMapping("/{id}/comments")
    public void saveComments(@PathVariable("id") String id,
                             @RequestBody Map<String, String> param) {
        String comment = param.get("comment");
        this.videoService.saveComments(id, comment);
    }

    @PostMapping("/comments/{id}/like")
    public Long likeComment(@PathVariable("id") String publishId) {

        return this.videoService.likeComment(publishId);
    }

    @PostMapping("/comments/{id}/dislike")
    public Long disLikeComment(@PathVariable("id") String publishId) {
        return this.videoService.disLikeComment(publishId);
    }
    @PostMapping("/{uid}/userFocus")
    public Object userFocus(@PathVariable("uid") Long uid) {
        return this.videoService.userFocus(uid);
    }
    @PostMapping("/{uid}/userUnFocus")
    public Object userUnFocus(@PathVariable("uid") Long uid) {
        return this.videoService.userUnFocus(uid);
    }

}
